import { reactive } from 'vue'
/**
* 数据 hook
* @param initValue 默认值
*/
export function useForm(initValue) {
  const form = reactive({ ...initValue })

  const resetForm = () => {
    Object.keys(form).forEach((key) => {
      form[key] = initValue ? initValue[key] : undefined
    })
  }

  const assignForm = (data) => {
    Object.keys(form).forEach((key) => {
      form[key] = data[key]
    })
  }

  return {
    form,
    // 重置为初始值
    resetForm,
    // 赋值不改变字段
    assignForm
  }
}
